package com.qcby.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcby.admin.dao.SysUserMapper;
import com.qcby.admin.form.UserAddForm;
import com.qcby.admin.form.UserPageForm;
import com.qcby.admin.model.SysUser;
import com.qcby.admin.service.SysUserService;
import com.qcby.admin.vo.UserListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-09-15
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {


    @Autowired
    private SysUserMapper UserMapper;
    @Override
    public boolean addUser(UserAddForm userForm) {

        List<UserAddForm> list=new ArrayList();


        return false;
    }

    @Override
    public UserListVo userList(UserPageForm userPageForm) {
        //初始化分页查询
        Page<SysUser> page=new Page<>(userPageForm.getPageNum(),userPageForm.getPageSize());
        LambdaQueryWrapper<SysUser> lqw=new LambdaQueryWrapper<>();
        //根据用户名模糊查询
        lqw.like(StringUtils.hasText(userPageForm.getUserName()),SysUser::getUserName,userPageForm.getUserName());
        //进行用户状态查询
        lqw.eq(StringUtils.hasText(userPageForm.getStatus()),SysUser::getStatus,userPageForm.getStatus());
        //进行手机号的搜索
        lqw.eq(StringUtils.hasText(userPageForm.getPhonenumber()),SysUser::getPhonenumber,userPageForm.getPhonenumber());
        Page<SysUser> resultPage=UserMapper.selectPage(page,lqw);
        UserListVo userListVo=new UserListVo();
        userListVo.setRows(resultPage.getRecords());
        userListVo.setTotal(resultPage.getTotal());
        return userListVo;
    }
}
